package com.hq.ims.data.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.entity.User;
import com.hq.ims.data.entityenum.EnumAccountStatus;
import com.hq.ims.data.entityenum.EnumCompanyLevel;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @since 20240920
 */
@Mapper
public interface UserMapstruct {

    UserMapstruct INSTANCE = Mappers.getMapper(UserMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    UserVo toUserVo(User source);

    default List<UserVo> toUserVoList(List<User> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toUserVo).collect(Collectors.toList());
    }

    //--------------------------------  --------------------------------

    @Mappings({
    })
    UserAndCompanySimpleVo toUserAndCompanySimpleVo(User source);

    default List<UserAndCompanySimpleVo> toUserAndCompanySimpleVoList(List<User> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toUserAndCompanySimpleVo).collect(Collectors.toList());
    }


    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class UserVo extends User {

        //企业注册状态
        private boolean isRegSuccess;

    }

    @ApiModel(value = "变更用户信息")
    @Data
    class ChangeUserInfoVo {

        @NotBlank(message = "用户ID不能为空")
        private String userId;

        @ApiModelProperty(value = "用户姓名")
        private String realName;

        @ApiModelProperty(value = "手机号")
        private String mobile;

        @ApiModelProperty(value = "身份证号")
        private String idCard;

        @ApiModelProperty(value = "头像")
        private String avatarUrl;

    }

    @ApiModel(value = "用户简要信息(用户,部门,公司)")
    @Data
    class UserAndCompanySimpleVo {

        @ApiModelProperty(value = "用户名称")
        private String userId;

        @ApiModelProperty(value = "员工Id")
        private String employeeId;

        @ApiModelProperty(value = "用户名称")
        private String realName;

        @ApiModelProperty(value = "手机号")
        private String mobile;

        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        @ApiModelProperty(value = "注册时间")
        private LocalDateTime registerTime;

        @ApiModelProperty(value = "用户头像")
        private String avatarUrl;

        @ApiModelProperty(value = "账号状态")
        private EnumAccountStatus accountStatus;

        @ApiModelProperty(value = "性别")
        private Boolean sex;

        @ApiModelProperty(value = "公司id")
        private String companyId;

        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @ApiModelProperty(value = "公司部门id")
        private String companyDepartmentId;

        @ApiModelProperty(value = "公司部门名称")
        private String companyDepartmentName;

        @ApiModelProperty(value = "是否部门负责人")
        private Boolean isDepartmentPrincipal;

        @ApiModelProperty(value = "是否公司管理员")
        private Boolean isCompanyAdmin;

        @ApiModelProperty(value = "公司级别")
        private EnumCompanyLevel companyLevel;

        @ApiModelProperty(value = "是否公司部门管理员")
        private Boolean isCompanyDepartmentPrincipal;

        @ApiModelProperty(value = "职务名称")
        private String jobName;

        @ApiModelProperty(value = "用户兼职的公司名称")
        private List<String> userPartTimeJobCompanyNameList;

        @ApiModelProperty(value = "用户角色")
        private List<PermissionRoleMapstruct.PermissionRoleIdAndNameVo> processRoleList;

    }

    @ApiModel(value = "包含经营信息统计")
    @Data
    class UserAndCompanyAndSimpleStatisticsSimpleVo extends UserAndCompanySimpleVo {

        @ApiModelProperty(value = "发布数量")
        private Integer publishBusinfoCount;

        @ApiModelProperty(value = "经营信息被接收数量")
        private Integer publishBusinfoBeReceiveCount;

        @ApiModelProperty(value = "经营信息已反馈数量")
        private Integer feedBackAlreadyDeliverTenderBeReceiveCount;

    }

    @Data
    @ApiModel("登陆成功返回对象")
    class SuccessLoginVo {

        @ApiModelProperty(value = "用户ID")
        private String userId;

        @ApiModelProperty(value = "凭证")
        private String token;

        @ApiModelProperty(value = "过期时间戳")
        private long tokenExpire;

    }

    @Data
    @ApiModel("登陆成功返回的状态")
    class LoginSuccessAfterReturnStatus {

        @ApiModelProperty(value = "注册新企业-审核中")
        private Boolean newCompanyAuditing;

        @ApiModelProperty(value = "注册新企业-未通过")
        private Boolean existsNewCompanyAuditNotPass;

        @ApiModelProperty(value = "注册新企业-审核已通过")
        private Boolean existsNewCompanyAuditPass;

        @ApiModelProperty(value = "待分配角色")
        private Boolean existsTodoDistributionRole;

        @ApiModelProperty(value = "被移除")
        private Boolean existsUnJoinCompany;

        @ApiModelProperty(value = "存在新公司撤回")
        private Boolean existsNewCompanyCancelAudit;

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

        @ApiModelProperty(value = "手机号")
        private String mobile;

        @ApiModelProperty(value = "用户姓名")
        private String realName;

        @ApiModelProperty(value = "性别")
        private Boolean sex;
    }

    @ApiModel(value = "手机号注册")
    @Data
    class MobileRegisterVo {

        @NotBlank(message = "用户手机号不能为空")
        @Length(max = 11, message = "手机号位数不正确")
        private String mobile;

        @NotBlank(message = "姓名不能为空")
        @Length(max = 4, message = "姓名")
        private String realName;

        @NotBlank(message = "短信验证码不能为空")
        private String smsCode;

        @NotBlank(message = "密码不能为空")
        private String pwd;

        @NotBlank(message = "确认密码不能为空")
        private String confirmPwd;

    }

    @ApiModel(value = "用户和公司一起注册")
    @Data
    class UserCompanyRegisterSaveVo extends MobileRegisterVo {

        @NotNull(message = "加入或注册企业不能为空", groups = {VdAdd.class})
        @ApiModelProperty(value = "是否注册新的企业")
        private Boolean isRegisterNewCompany;

        @NotNull(message = "新公司不能为空", groups = {VdRegisterNewCompany.class})
        @ApiModelProperty(value = "新公司")
        private CompanyMapstruct.UserRegisterNewCompanySaveVo userRegisterNewCompanySaveVo;

        @NotBlank(message = "加入新公司不能为空", groups = {VdJoinCompany.class})
        @ApiModelProperty(value = "加入新公司")
        private String joinCompanyId;


    }

    @ApiModel(value = "平台添加用户")
    @Data
    class PlatformAddUserVo {

        @NotBlank(message = "用户手机号不能为空")
        @Length(max = 11, message = "手机号位数不正确")
        private String mobile;

        @NotBlank(message = "用户姓名不能为空")
        private String realName;

        @NotBlank(message = "用户角色不能为空")
        private String permissionRoleId;

        @ApiModelProperty("账号状态")
        private EnumAccountStatus accountStatus;

        @ApiModelProperty("密码")
        private String pwd;

        @NotBlank(message = "公司部门ID不能为空")
        private String companyDepartmentId;

    }

    @ApiModel(value = "找回密码")
    @Data
    class ForgotPasswordVo {

        @NotBlank(message = "用户手机号不能为空")
        @Length(max = 11, message = "手机号位数不正确")
        private String mobile;

        @NotBlank(message = "密码不能为空")
        private String pwd;

    }

    //-------------------------------- 以下为自定义类[其它] --------------------------------

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    class UserLoginLockVo {

        /**
         * 密码错误次数
         */
        private Integer accountPwdErrorCount;

        /**
         * 解锁时间
         */
        private LocalDateTime unLockTimme;

        /**
         * 是否长时间锁定
         */
        private Boolean isLongtimeLock;

    }

    //-------------------------------- springboot验证标识 --------------------------------
    interface VdRegisterNewCompany {
    }

    interface VdJoinCompany {
    }

}
